{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>业务订单</h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="collapse" id="searchBox">
                        <div class="layui-form layui-form-item">
                            <div class="layui-col-md6 layui-input-inline">
                                <input type="text" id="key" class="layui-input search" name="key" value="" placeholder="订单号"/>
                            </div>
                            <div class="layui-input-inline">
                                <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                                <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                            </div>
                        </div>
                    </div>
                </div>
                <!--搜索框结束-->
                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group pull-left" >
                        <a href="javascript:;" onclick="tableReload()" class="btn btn-success" data-toggle="tooltip" title="" data-original-title="刷新表格" data-placement="auto">
                            <i class="fa fa-refresh"></i>
                        </a>
                        <!--<a href="javascript:;" onclick="wk.layer_show('添加管理员','{:url('userAdd')}',900)">-->
                            <!--<button class="btn btn-primary" type="button">-->
                                <!--<i class="fa fa-plus"></i> 添加管理员-->
                            <!--</button>-->
                        <!--</a>-->
                        <!--<button  class="btn btn-danger" href="javascript:;" data-toggle="dropdown">-->
                            <!--<i class="fa fa-wrench"></i> 批量操作 <span class="caret"></span>-->
                        <!--</button>-->
                        <!--<ul class="dropdown-menu animated fadeInDown" role="menu">-->
                            <!--<li><a href="javascript:;" class="layuiBtn" data-type="getCheckData"><i class="fa fa-trash-o"></i> 批量删除 </a></li>-->
                            <!--<li><a  href="javascript:;" class="layuiBtn" data-type="usingAll" id="onAll" data-toggle="tooltip" data-original-title="若未勾选默认启用全部" data-placement="auto"><i class="fa fa-check-circle"></i> 批量启用</a></li>-->
                            <!--<li><a  href="javascript:;" class="layuiBtn" data-type="forbiddenAll" id="offAll" data-toggle="tooltip" data-original-title="若未勾选默认禁用全部" data-placement="auto"><i class="fa fa-ban"></i> 批量禁用</a></li>-->
                            <!--<li><a  href="javascript:;" class="layuiBtn" data-type="excelAll" id="excel" data-toggle="tooltip" data-original-title="导出筛选完成数据" data-placement="auto"><i class="fa fa-print"></i> 导出Excel</a></li>-->
                        <!--</ul>-->
                    </div>
                    <div class="input-group pull-right" data-toggle="tooltip" title="" data-original-title="搜索">
                        <button class="btn btn-primary" data-toggle="collapse"
                                data-target="#searchBox" >
                            <i class="glyphicon glyphicon-search"></i>
                        </button>
                    </div>
                </div>
                <!--操作框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>
                    <!--等级模板-->
                    <script type="text/html" id="titleTpl">
                        {{# if(d.o_level == 1){ }}
                        本人
                        {{# }else if(d.o_level == 2){ }}
                        2级直属
                        {{# }else{ }}
                        3级直属
                        {{# } }}
                    </script>
                    <!--支付方式模板-->
                    <script type="text/html" id="payTpl">
                        {{# if(d.o_type==1){ }}
                        支付宝
                        {{# }else{ }}
                        微信
                        {{# } }}
                    </script>
                    <!--状态模板-->
                    <script type="text/html" id="staBar">
                        {{# if(d.o_status==1){ }}
                        未付款
                        {{# }else{ }}
                        已付款
                        {{# } }}
                    </script>
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        {{# if(d.o_status == 2 && d.o_agree == 1){ }}
                        <a href="javascript:;" onclick="agreeshop('{{d.o_id}}')" class="btn btn-danger btn-xs m-r-xs" title="商户入驻审核"><i class="fa fa-thumb-tack"></i></a>
                        {{# } }}
                        <a href="javascript:;" onclick="wk.href('{:url('shopDetail')}?id={{d.o_number}}')" class="btn btn-danger btn-xs m-r-xs" title="详情"><i class="fa fa-eye"></i></a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<audio src="/static/admin/music/default.mp3" controls="controls" preload id="music1" hidden></audio>
<!--<div id="small-chat" class="animated bounceInUp " style="display:none;" onclick="$('#small-chat').hide();">-->
    <!--&lt;!&ndash;<span class="badge badge-warning pull-right"></span>&ndash;&gt;-->
    <!--<span class="layui-badge-dot layui-bg-orange pull-right"></span>-->
    <!--<a class="open-small-chat">-->
        <!--<i class="fa fa-comments"></i>-->
    <!--</a>-->
<!--</div>-->
{include file="public/footer" /}
<script>
    var flag = 0
    //layui渲染数据表格
    layui.use(['table','util'], function () {
        var table = layui.table
            , form = layui.form
            , util = layui.util
        table.render({
            elem: '#test'
            , url: '{:url("Salesman/order")}'
            , page: true
            , even: false //开启隔行背景
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            // ,width:100
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type:'numbers', width: 80, title: '序号'}
                , {field: 'o_number', width: 220, title: '订单号', align: 'center'}
                , {width: '', title: '业务员名称', align: 'center',templet:'<div>{{d.s_name ? d.s_name : ""}}{{d.uname ? d.uname : ""}}</div>'}
                , {field: 'o_user_pay', width: '', title: '金额', align: 'center'}
                , {field: 'o_datetime', width: 180, title: '下单时间', align: 'center'}
                , {field: 'o_level', width: '', title: '等级', align: 'center',templet:'#titleTpl'}
                , {field: 'o_type', width: '', title: '支付方式',align: 'center', templet: '#payTpl'}
                , {field: 'o_status', width: '', title: '状态',align: 'center', templet: '#staBar'}
                , {field: 'o_admin', width: '', title: '审核人',align: 'center'}
                , {fixed: 'right', width: 100, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function(res, curr, count){
                var i = 0,
                    num = 0;
                $.each(res.data,function(index,item){
                    if(item['o_status'] == 2 && item['o_agree'] == 1 && item['o_music'] == 1){
                        i++;
                        wk.change(item['o_id'],"{:url('music')}",'o_music','2')
                    }
                    if(item['o_status'] == 2 && item['o_agree'] == 1){
                        num ++;
                    }
                });
                if(i > 0 && flag > 0){
                    var audio = document.getElementById('music1');
                    audio.play();
                    $('#small-chat').show();
                    // $('#small-chat').find('span').first().text(num);
                }
                if(i > 0 && flag == 0){
                    layer.msg('您有 <span style="color:#ed5565;font-weight: bold;font-size:16px;">' + num + '</span> 个新订单，待处理...',{time:1500});
                }
                flag++;
            }
        });
    });
    function agreeshop(id){
        layer.confirm('入驻同意吗？', {
            btn: ['同意','拒绝'] //按钮
        }, function(){
            shopchange(2,id)
        }, function(){
            layer.prompt({
                formType: 2,
                value: '',
                title: '拒绝理由',
                area: ['800px', '350px'] //自定义文本域宽高
            }, function(value, index, elem){
                layer.close(index);
                shopchange(3,id,value)
            });
        });
    }

    function shopchange(type,id,value){
        var value = value ? value : '';
        $.ajax({
            url:"{:url('agreeshop')}",
            type:'post',
            data:'type='+type+'&id='+id + '&value=' + value,
            dataType:'json',
            success:function(res){
                if(res.code == 200){
                    layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                        //重载当前页表格
                        $(".layui-laypage-btn").click();
                    })
                }else if(res.code == 100){
                    wk.error(res.msg,'',2);
                }
            }
        })
    }
    setInterval("$('.layui-laypage-btn').click();",10000);
</script>
</body>
</html>